package com.sentinel.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@SuppressWarnings({"all"})
public class Result {
    // 1为成功 其他为失败
    private int code;
    // 返回信息, 一般用于失败信息
    private String message;
    // 返回数据, 一般用于成功返回
    private Object data;

    /**
     * 根据条件判断是否成功
     * @param condition 条件
     * @return 结果
     */
    public static Result of(boolean condition) {
        return of(condition, "失败");
    }

    public static Result of(boolean condition, String failureMessage) {
        return of(condition, "", failureMessage);
    }

    public static Result of(boolean condition, Object data, String failureMessage) {
        return condition ? success(data) : failure(failureMessage);
    }

    // 静态方法：返回成功结果
    public static Result success() {
        return success(null);
    }

    public static Result success(Object data) {
        return new Result(1, "成功", data);
    }


    // 静态方法：返回失败结果
    public static Result failure(String message) {
        return failure(0, message);
    }

    public static Result failure(int code, String message) {
        return new Result(code, message, null);
    }
}

